<%@ page language="java" contentType="text/html" pageEncoding="utf-8"%>
<%@include file="/WEB-INF/pages/common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <%@include file="/WEB-INF/pages/common/head.jsp"%>
    <title><spring:message code="title.part"/></title>
    <script type="text/javascript">
        var datagrid;
        var message =$.messager;
        var operateDialog;
        $(function() {
            datagrid=$('#datagrid').datagrid({
                url : '${path}/business/ipic_system/claim_field/ajaxList.do',
                onLoadSuccess:function(){
                    datagrid.datagrid('clearSelections');
                },
                rowStyler: function(index,row){
                    if(row['closeDateActualStr']==null || row['closeDateActualStr']==''){
                        return 'background-color:yellow';
                    }else if(row['startDateStr']!=null || row['startDateStr']!=''){
                        var startDate=(new Date((row['startDateStr']).replace(/-/g,"/"))).getTime();
                        var actualCloseDate=(new Date((row['closeDateActualStr']).replace(/-/g,"/"))).getTime();
                        if((actualCloseDate-startDate)>20*24*60*60*1000){
                            return 'background-color:#bc8f8f;';
                        }else{
                            return 'background-color:#adff2f;';
                        }
                    }
                }
            });
        });

        function workshopCodeFormatter(value,row,index){
        <c:forEach var="dict" items="${dictWorkshopList}">
            if(row['workshopCode']=='${dict.code}'){
                return '${dict.name}';
            }
        </c:forEach>
        }
        function findPlaceFormatter(value,row,index){
        <c:forEach var="dict" items="${dictFindPlaceList}">
            if(row['findPlace']=='${dict.code}'){
                return '${dict.name}';
            }
        </c:forEach>
        }
        function manageBodyFormatter(value,row,index){
        <c:forEach var="dict" items="${dictManageBodyList}">
            if(row['manageBody']=='${dict.code}'){
                return '${dict.name}';
            }
        </c:forEach>
        }
        function claimStatusFormatter(value,row,index){
        <c:forEach var="dict" items="${dictClaimStatusList}">
            if(row['claimStatus']=='${dict.code}'){
                return '${dict.name}';
            }
        </c:forEach>
        }
        function claimTypeFormatter(value,row,index){
        <c:forEach var="dict" items="${dictClaimTypeList}">
            if(row['claimType']=='${dict.code}'){
                return '${dict.name}';
            }
        </c:forEach>
        }
        //子页面返回方法
        function returnResult(){
            operateDialog.dialog('close');
            datagrid.datagrid('unselectAll');
            datagrid.datagrid('reload');
        }
        //判断选择单据是否是一条
        function isChooseOne(rows){
            var flag = false;
            if(rows.length >1 ) {
                message.show({
                    msg : "<spring:message code='msg.choose' arguments='"+rows.length+"'/>",
                    title : '<spring:message code='msg.tip'/>'
                });
                flag = false;
            } else if (rows.length == 0) {
                message.show({
                    msg : "<spring:message code='msg.please.choose'/>",
                    title : '<spring:message code='msg.tip'/>'});
                flag = false;
            }else{
                flag = true;
            }
            return flag;
        }
        function getSelectedIds(){
            var rows = datagrid.datagrid("getSelections");
            if (rows.length > 0) {
                var ids = [];
                for ( var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                return ids;
            }else{
                $.messager.alert('<spring:message code='msg.error'/>','<spring:message code='msg.delete'/>','error');
                return null;
            }
        }
        function append(title,href) {
            //弹出层的相关参数
            operateDialog = $("#operateDialog").dialog({
                title : title,collapsible:true,maximizable:true,
                width : 900,
                height: 500,
                buttons : [{
                    iconCls:"icon-save",
                    text : '<spring:message code='button.save'/>',
                    handler : function() {
                        $("#operateIFrame")[0].contentWindow.save_();
                    }
                },{
                    iconCls:"icon-no",
                    text : '<spring:message code='button.close'/>',
                    handler : function() {
                        //关闭按钮的时候进行关闭按钮
                        operateDialog.dialog('close');
                    }
                }]
            });
            $("#operateIFrame")[0].src=imonJYRH.url(href);
            operateDialog.dialog('open');
            imonJYRH.showZone();
        }
        function add_() {
            var href = '${path}/business/ipic_system/claim_field/addUI.do';
            var title = '<spring:message code='msg.create'/>';
            append(title,href);
        }
        function modify_(){
            var rows = datagrid.datagrid("getSelections");
            if(!isChooseOne(rows)){return;}
            var href = '${path}/business/ipic_system/claim_field/modifyUI.do?id='+rows[0]['id'];
            var title = '<spring:message code='msg.create'/>';
            append(title,href);
        }
        function delete_(){
            var ids = getSelectedIds();;
            $.messager.confirm(
                    '<spring:message code='msg'/>',
                    '<spring:message code='msg.confirm.delete'/>',
                    function(r){
                        if (r && null!=ids){
                            imonJYRH.showZone();
                            $.ajax({
                                url : imonJYRH.url("${path}/business/ipic_system/claim_field/ajaxDelete.do"),
                                cache : false,
                                data :{'ids':ids.join(',')},
                                success : function(reMsg) {
                                    if(reMsg.success){
                                        search_();
                                        message.show({
                                            msg : reMsg.msg,
                                            title : '<spring:message code='msg.tip'/>',
                                            showType:'slide'
                                        });
                                    }else{
                                        message.alert('<spring:message code='msg.tip'/>',reMsg.msg);
                                    }
                                    imonJYRH.hideZone();
                                }
                            });
                        }
                    });
        }
        function search_() {
            datagrid.datagrid('unselectAll');
            datagrid.datagrid('load', imonJYRH.serializeObject($("#tableForm *")));
        }
        function reset_(){
            $("#tableForm *").each(function(){
                $(":input:not(:checkbox,:radio)",this).val("");
            });
        }
    	/**
    	 *0公里导出
    	 */
    	function export_() {
    	    var rows = datagrid.datagrid("getSelections");
    	    var ids = [];
            if (rows.length > 0) {
            	if(rows.length==1){
                     for ( var i = 0; i < rows.length; i++) {
                         ids.push(rows[i].id);
                     }
                     $.messager.confirm('提示', '确定导出数据？', function(r) {
         				if (r) {
         					var url = "${path}/excel/claimFieldExcel/exportExcel.do";
         					url += "?ids=" + ids;
         					$("#claimFieldForm").attr("action", url).submit();
         				} else {
         					return;
         				}
         			});
            	}else{
            		$.messager.alert('<spring:message code='msg.error'/>','请选择一项进行导出','error');
            		return
            	}
            }else{
                $.messager.alert('<spring:message code='msg.error'/>','请选择','error');
                return;
            }
    	}
    	/**
    	 *0公里打印
    	 */
    	function print_() {
    	    var rows = datagrid.datagrid("getSelections");
    	    var ids = [];
            if (rows.length > 0) {
            	if(rows.length==1){
                     for ( var i = 0; i < rows.length; i++) {
                         ids.push(rows[i].id);
                     }
                     $.messager.confirm('提示', '确定导出数据？', function(r) {
         				if (r) {
         					var url = "${path}/excel/claimFieldExcel/exportPdf.do";
         					url += "?ids=" + ids;
         					$("#claimFieldForm").attr("action", url).submit();
         				} else {
         					return;
         				}
         			});
            	}else{
            		$.messager.alert('<spring:message code='msg.error'/>','请选择一项进行打印','error');
            		return
            	}
            }else{
                $.messager.alert('<spring:message code='msg.error'/>','请选择','error');
                return;
            }
    	}
    </script>
</head>
<body class="easyui-layout">
 	<form id="claimFieldForm"  
		method="post">
<div data-options="region:'north'" style="overflow: hidden;height: 90px;">
    <div class="datagrid-toolbar" style="height: auto">
        <br/>
        <fieldset>
            <legend><spring:message code="label.condition"/></legend>
            <table id="tableForm" width="100%">
                <tr>
                    <td align="right"><spring:message code="label.claim.code"/>：</td>
                    <td>
                        <input type="text" name="code"/>
                    </td>
                    <td align="right"><spring:message code="label.supplier.code"/>：</td>
                    <td>
                        <input type="text" name="supplierCode"/>
                    </td>
                    <td align="right"><spring:message code="label.part.code"/>：</td>
                    <td>
                        <input type="text" name="partCode"/>
                    </td>
                </tr>
            </table>
        </fieldset>
        <br/>
    </div>
</div>
<div data-options="region:'center'">
    <div id="tb">
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-search" onclick="search_();"><spring:message code="bar.command.search"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-undo" onclick="reset_();"><spring:message code="bar.command.reset"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-add" onclick="add_();"><spring:message code="bar.command.add"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-edit" onclick="modify_();"><spring:message code="bar.command.modify"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-cancel" onclick="delete_();"><spring:message code="bar.command.delete"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-import" onclick="export_();"><spring:message code="bar.command.export"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-view" onclick=""><spring:message code="bar.command.view"/></a>
         <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-print" onclick="print_()">导出PDF</a>
    </div>
    <table id="datagrid" width="100%"
           data-options="toolbar:'#tb',striped:true,fit:true,pagination:true,idField:'id',rownumbers:true">
        <thead data-options="frozen:true">
        <tr>
            <th data-options="checkbox:'true',field:'ck'" rowspan="2"></th>
            <th data-options="align:'center',width:'100',field:'code'" rowspan="2"><spring:message code="table.head.claim.code"/></th>
        </tr>
        </thead>
        <thead>
        <tr>
            <th data-options="align:'center',width:'120',field:'supplierCode'" rowspan="2"><spring:message code="table.head.supplier.code"/></th>
            <th data-options="align:'center',width:'120',field:'supplierName'" rowspan="2"><spring:message code="table.head.supplier.name"/></th>
            <th data-options="align:'center',width:'120',field:'partCode'" rowspan="2"><spring:message code="table.head.part.code"/></th>
            <th data-options="align:'center',width:'120',field:'partName'" rowspan="2"><spring:message code="table.head.part.name"/></th>
            <th data-options="align:'center',width:'100',field:'manufactureDateStr'" rowspan="2"><spring:message code="table.head.claim.manufacture.date"/></th>
            <th data-options="align:'center',width:'120',field:'deliveryBatchCode'" rowspan="2"><spring:message code="table.head.claim.delivery.batch.code"/></th>
            <th data-options="align:'center',width:'60',field:'lotSize'" rowspan="2"><spring:message code="table.head.claim.lot.size"/></th>
            <th data-options="align:'center',width:'80',field:'workshopCode',formatter:workshopCodeFormatter" rowspan="2"><spring:message code="table.head.claim.workshop.code"/></th>
            <th data-options="align:'center',width:'90',field:'findPlace',formatter:findPlaceFormatter" rowspan="2"><spring:message code="table.head.claim.find.place"/></th>
            <th data-options="align:'center',width:'100',field:'startDateStr'" rowspan="2"><spring:message code="table.head.claim.start.date"/></th>
            <th data-options="align:'center',width:'100',field:'closeDatePlanStr'" rowspan="2"><spring:message code="table.head.claim.close.date.plan"/></th>
            <th data-options="align:'center',width:'100',field:'closeDateActualStr'" rowspan="2"><spring:message code="table.head.claim.close.date.actual"/></th>
            <th data-options="align:'center',width:'100',field:'manageBody',formatter:manageBodyFormatter" rowspan="2"><spring:message code="table.head.claim.manage.body"/></th>
            <th data-options="align:'center',width:'100',field:'claimStatus',formatter:claimStatusFormatter" rowspan="2"><spring:message code="table.head.claim.claim.status"/></th>
            <th data-options="align:'center',width:'100',field:'notQualifiedReportCode'" rowspan="2"><spring:message code="table.head.claim.not.qualified.report.code"/></th>
            <th data-options="align:'center',width:'100',field:'problemDesc'" rowspan="2"><spring:message code="table.head.claim.problem.desc"/></th>
            <th align="center" colspan="6"><spring:message code="table.head.claim.situation"/></th>
            <th data-options="align:'center',width:'120',field:'amountNotQualified'" rowspan="2"><spring:message code="table.head.claim.amount.not.qualified"/></th>
            <th data-options="align:'center',width:'120',field:'claimType',formatter:claimTypeFormatter" rowspan="2"><spring:message code="table.head.claim.claim.type"/></th>
            <th data-options="align:'center',width:'120',field:'reporterCode'" rowspan="2"><spring:message code="table.head.claim.reporter.code"/></th>
            <th data-options="align:'center',width:'120',field:'reporterName'" rowspan="2"><spring:message code="table.head.claim.reporter.name"/></th>
            <th data-options="align:'center',width:'120',field:'affectParts'" rowspan="2"><spring:message code="table.head.claim.affect.parts"/></th>
            <th data-options="align:'center',width:'120',field:'comment'" rowspan="2"><spring:message code="table.head.claim.comment"/></th>
            <th data-options="align:'center',width:'120',field:'customerClaimPart'" rowspan="2"><spring:message code="table.head.claim.customer.claim.part"/></th>
            <th data-options="align:'center',width:'120',field:'supplierAcceptPart'" rowspan="2"><spring:message code="table.head.claim.supplier.accept.part"/></th>
            <th data-options="align:'center',width:'120',field:'lastYearReceivePart'" rowspan="2"><spring:message code="table.head.claim.last.year.receive.part"/></th>
            <th data-options="align:'center',width:'120',field:'ppms'" rowspan="2"><spring:message code="table.head.claim.ppms"/></th>
            <th align="center" colspan="2"><spring:message code="table.head.claim.incoming"/></th>
        </tr>
        <tr>
            <th data-options="align:'center',width:'70',field:'cs4Str'"><spring:message code="table.head.claim.cs4"/></th>
            <th data-options="align:'center',width:'70',field:'cs5Str'"><spring:message code="table.head.claim.cs5"/></th>
            <th data-options="align:'center',width:'70',field:'cs6Str'"><spring:message code="table.head.claim.cs6"/></th>
            <th data-options="align:'center',width:'70',field:'cs7Str'"><spring:message code="table.head.claim.cs7"/></th>
            <th data-options="align:'center',width:'70',field:'cs8Str'"><spring:message code="table.head.claim.cs8"/></th>
            <th data-options="align:'center',width:'70',field:'cs9'"><spring:message code="table.head.claim.cs9"/></th>
            <th data-options="align:'center',width:'70',field:'ppmAtNumber'"><spring:message code="table.head.claim.ppm.at.number"/></th>
            <th data-options="align:'center',width:'70',field:'closed'"><spring:message code="table.head.claim.closed"/></th>
        </tr>
        </thead>
    </table>
</div>
</form>
<div id="operateDialog" class="easyui-dialog"
     data-options="iconCls:'icon-save',resizable:true,modal:true,closed: true,collapsible:true,maximizable:true">
    <iframe scrolling="auto" id='operateIFrame' frameborder="0"  src="" style="width:100%;height:100%;"/>
</div>
</body>
</html>